/*
 * @Description: loading状态
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-03-30 21:55:02
 * @LastEditTime: 2021-03-31 15:37:25
 */
import { ref, Ref, unref, computed, watch } from 'vue'

export function useLoading(props: Ref<any>) {
	const loadingRef = ref(unref(props).loading)

	watch(
		() => unref(props).loading,
		loading => {
			loadingRef.value = loading
		}
	)

	const getLoading = computed(() => unref(loadingRef))

	function setLoading(loading: boolean) {
		loadingRef.value = loading
	}

	return { getLoading, setLoading }
}
